# name : gsDesign.nBinomial.delta.mdd prop
# key : gsDesign.nBinomial.delta.mdd
# expand-env: ((yas-indent-line 'fixed) (yas-wrap-around-region 'nil))
# contributor: Shuguang Sun
# --
${1:nbinomial_delta_mdd} <- function (x) {
  # x from nBinomial with outtype = 3
  c <- 1/(1 + x$ratio)
  psi <- c * (1 - c)
  if (is.null(x$delta0)) {
      x$delta0 <- 0
  }
  zalpha <- -stats::qnorm(x$alpha/x$sided)
  ## deltaHat <- zalpha * sqrt((1 + x$ratio)/x$n) *
  ##             sqrt((1 - x$p2)*x$p2 + (1 - x$p2)*x$p2/x$ratio) + x$delta0
  deltaHat <- zalpha * x$sigma0 * sqrt(1/x$n) + x$delta0
  deltaHat
}
$1(x)
